package com.ruoyi.system.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.ruoyi.system.domain.SysUnitWord;
import com.ruoyi.system.mapper.SysUnitWordMapper;
import com.ruoyi.system.service.ISysUnitWordService;

/**
 * 班级管理 服务层实现
 * 
 * @author ruoyi
 */
@Service
public class SysUnitWordServiceImpl implements ISysUnitWordService
{

    @Autowired
    private SysUnitWordMapper sysUnitWordMapper;



    /**
     * 批量选择单词加入单元
     * 
     * @param unitId 但愿ID
     * @param wordIds 单词ID数组
     * @return 结果
     */
    @Override
    @Transactional
    public int batchInsertUnitWord(Long unitId, Long[] wordIds)
    {
        // 新增班级与学员关联
        List<SysUnitWord> list = new ArrayList<SysUnitWord>();
        for (Long wordId : wordIds)
        {
        	SysUnitWord entity = new SysUnitWord();
            entity.setUnitId(unitId);
            entity.setWordId(wordId);
            list.add(entity);
        }
        
        sysUnitWordMapper.deleteUnitWordByUnitId(unitId);
        return sysUnitWordMapper.batchInsertUnitWord(list);
    }

    /**
     * 批量取消单元和单词关联
     * 
     * @param unitId 班级ID
     * @param wordIds 需要删除的单词ID数组
     * @return 结果
     */
    @Override
    public int deleteUnitWordByUnitId(Long unitId)
    {
        return sysUnitWordMapper.deleteUnitWordByUnitId(unitId);
    }
}